// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var leftMenu = require("../leftMenu/leftMenu");
	var topMenu = require("../topMenu/topMenu");
	var footer = require("../footer/footer_main");
	var router = require("../hash/pageRouter");
	var dialog = require("dialog");
	var validate = require("validate");
	var databind = require("databind");
	var css_detail_info = require("./replenishConfirm.css");
	var html_auditBailAddition = require("./html_auditBailAddition.html");
	var constant = require("constant");
	var enterpriseId;
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var init = function() {
		footer.init();
		$("#footer").removeClass("none");
		leftMenu.init(5);
		topMenu.init(1);
		$(".footer").removeClass("none");
		$(".table-section").removeClass("none");
		$("#leftMenu6 .replenishConfirm").addClass("leftMenu-active");
		$("#leftMenu6 .leftMenu li:first-child").addClass("leftMenu-open");
		inquireFinanceCreditPageList();
		initEvent();
	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
		
		$("#bailAuditSearch").unbind("click").click(function(){
			inquireFinanceCreditPageList();
		});
		
		//已完成融资
		$(".endFinanceList").unbind("click").click(function() {
			location.href = "../financing/endFinanceList.html";
		});
		//收货通知查询
		$(".recieveNoticeList").unbind("click").click(function() {
			location.href = "../financing/recieveNoticeList.html";
		});
		//放货查询
		$(".deliveryNoticeList").unbind("click").click(function() {
			location.href = "../financing/deliveryNoticeList.html";
		});
		//放款单查询
		$(".loanNoticeList").unbind("click").click(function() {
			location.href = "../financing/loanNoticeList.html";
		});
	};

	//查询保证金追加列表
	var inquireFinanceCreditPageList = function() {
		base.fnAjax({
			action: "inquireFinanceCreditPageList.json",
			oData: {
				pageIndex: pageIndex,
				pageSize: pageSize,
				adjustment: 3,
				auditState: $("#bailAdditionaudit .auditState").val()
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $("#bailAdditionTpl").html();
					var html = juicer(tpl, data);
					$("#bailAdditionTable").html(html);
					
					$(".detail").unbind("click").click(function(){
						router.route("financing/replenishConfirmDetail.html?creditId=" + $(this).parents("tr").attr("creditId"))
					});
					
					totalPageCount = data.totalPageCount;
                    totalRecordCount = data.totalRecordCount;
                    base.pageControl(
                    	$("#bailAdditionaudit .pagerCon"),
                        totalRecordCount,
                        data.pageIndex,
                        data.pageSize,
                        function(p) {
                            pageIndex = p;
                            inquireFinanceCreditPageList();
                    });
				} else {
					base.alert(3, data.message);
				}
			}
		});
	}
	
	return {
		init: init
	};
});